namespace ASPNET.StarterKit.IssueTracker.BusinessLogicLayer
{
    using ASPNET.StarterKit.IssueTracker.DataAccessLayer;
    using System;

    public class Query
    {
        private int _Id;
        private string _Name;

        public Query(int id, string name)
        {
            this._Id = id;
            this._Name = name;
        }

        public static bool DeleteQuery(int queryId)
        {
            if (queryId <= DefaultValues.GetQueryIdMinValue())
            {
                throw new ArgumentOutOfRangeException("queryId");
            }
            return DataAccessLayerBaseClassHelper.GetDataAccessLayer().DeleteQuery(queryId);
        }

        public static QueryCollection GetQueriesByUsername(string username, int projectId)
        {
            if ((username == null) || (username.Length == 0))
            {
                throw new ArgumentOutOfRangeException("username");
            }
            if (projectId <= DefaultValues.GetProjectIdMinValue())
            {
                throw new ArgumentOutOfRangeException("projectId");
            }
            return DataAccessLayerBaseClassHelper.GetDataAccessLayer().GetQueriesByUsername(username, projectId);
        }

        public static bool SaveQuery(string username, int projectId, string queryName, QueryClauseCollection queryClauses)
        {
            if ((username == null) || (username.Length == 0))
            {
                throw new ArgumentOutOfRangeException("username");
            }
            if (projectId <= DefaultValues.GetProjectIdMinValue())
            {
                throw new ArgumentOutOfRangeException("projectId");
            }
            if ((queryName == null) || (queryName.Length == 0))
            {
                throw new ArgumentOutOfRangeException("queryName");
            }
            if (queryClauses.Count == 0)
            {
                throw new ArgumentOutOfRangeException("queryClauses");
            }
            return DataAccessLayerBaseClassHelper.GetDataAccessLayer().SaveQuery(username, projectId, queryName, queryClauses);
        }

        public int Id
        {
            get
            {
                return this._Id;
            }
        }

        public string Name
        {
            get
            {
                return this._Name;
            }
        }
    }
}

